package com.only4play.practice.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author mdy
 * * @date 2024/9/13
 */
@Slf4j
@Component
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime",  new Date(), metaObject);
        this.setFieldValByName("updateTime",  new Date(), metaObject);

        //        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
//        this.setFieldValByName("updateTime",  LocalDateTime.now(), metaObject);
        // TODO 其他属性填充
    }

    @Override
    public void updateFill(MetaObject metaObject) {

        this.setFieldValByName("updateTime",  new Date(), metaObject);


        // TODO 其他属性填充

    }
}
